package com.emiage.ddutils;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created by LiJZ on 2016/7/22.
 */
public class StreamUtils {

	/**
	 * 读取一个流，把流的内容转为字符串
	 * 可由字符串转为byte[] 格式
	 * @param is
	 * @return
	 * @throws IOException
	 */
	public static String streamToString(InputStream is) throws IOException {
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		byte[] buff = new byte[1024];
		int len = -1;
		while ((len = is.read(buff)) != -1) {
			baos.write(buff, 0, len);
		}
		is.close();
		String str = baos.toString();
		baos.close();
		return str;
	}
}
